package planit.communication;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;

import planit.model.Schedule;

public class HarddiskDataHandler implements DataHandler {

	@Override
	public void commitAllData(Schedule data) {

		FileOutputStream fos = null;
		ObjectOutputStream out = null;
		try
		{
			fos = new FileOutputStream("schema.ser");
			out = new ObjectOutputStream(fos);
			out.writeObject(data);
			out.close();
		}
		catch(IOException ex)
		{
			ex.printStackTrace();
		}

		
	}

	@Override
	public Schedule getAllData() {
		Schedule data = null;
		FileInputStream fis = null;
		ObjectInputStream in = null;
		try
		{
			fis = new FileInputStream("schema.ser");
			in = new ObjectInputStream(fis);
			data = (Schedule)in.readObject();
			in.close();
		}
		catch(IOException ex)
		{
			ex.printStackTrace();
		}
		catch(ClassNotFoundException ex)
		{
			ex.printStackTrace();
		}

		return data;
	}

}
